using UnityEngine;

namespace Framework.Core
{
    public abstract class ModuleSingleton<T> where T : class, IModule, new()
    {
        private static T _instance;
        public static T Instance
        {
            get
            {
                if (_instance == null)
                    Debug.LogError($"Module {typeof(T)} not created。");

                return _instance;
            }
        }

        protected ModuleSingleton()
        {
            if (_instance != null)
                Debug.LogError($"Module {typeof(T)} has been created。");
            _instance = this as T;
        }

        protected void Destroy()
        {
            _instance = null;
        }
    }
}